package com.sky.mapper;


import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderDetailMapper {
    /**
     * 向订单详情表插入数据
     * @param orderDetail
     */
    void insert(OrderDetail orderDetail);

    /**
     * 根据订单id查找订单详情
     * @param orderId
     * @return
     */
    @Select("select * from order_detail where order_id = #{orderId}")
    List<OrderDetail> findByOrderId(Long orderId);

//    /**
//     * top10统计
//     * @param begin
//     * @param end
//     * @return
//     */
//
////    @Select("select name,sum(number) as number from order_detail group by name order by number desc limit 10")
//    @Select("    select od.name,sum(od.number) as number from orders o,order_detail od where od.order_id = o.id and o.status = 5 and o.order_time between #{begin} and #{end} group by od.name order by number desc limit 10")
//    List<OrderDetail> findByTime(String begin, String end);
    /**
     * 视频top10统计
     * @param begin
     * @param end
     * @return
     */

//    @Select("select name,sum(number) as number from order_detail group by name order by number desc limit 10")
    @Select("select od.name,sum(od.number) as number from orders o,order_detail od where od.order_id = o.id and o.status = 5 and o.order_time between #{begin} and #{end} group by od.name order by number desc limit 10")
    List<GoodsSalesDTO> findByTime(LocalDateTime begin, LocalDateTime end);
}
